<template>
  <div class="comment-reply">
    <van-nav-bar >
     <span slot="title">
        {{curComment.reply_count > 0 ? `有${curComment.reply_count}条回复` : '暂无回复'}}
     </span>
      <template #right>
      <van-icon name="close" @click="$emit('close')"></van-icon>
      </template>
    </van-nav-bar>

    <van-cell class="page-bg" title="评论项内容"></van-cell>
    <comment-item :comment="curComment"></comment-item>
    
    <van-cell class="page-bg" title="回复列表"></van-cell>
    <comment-list 
    :list="commentReplyList"
    type='c'
    :sourceId="curComment.com_id" 
    ></comment-list>

    <van-popup v-model="commentReplyShow" position="bottom">
     <comment-reply 
     type='c' 
     :target="curComment.com_id"  
     @update-list="updataList"
     ></comment-reply>
   </van-popup>
  <!-- 底部区域 -->
         <div class="article-bottom">
            <van-button
                class="comment-btn"
                round
                size="small"
                @click="commentReplyShow=true"
              >写评论</van-button>
         </div>
    <!-- /底部区域 -->

    <!-- 发布评论 -->
 
    <!-- /发布评论 -->
  </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import CommentList from './comment-list.vue'
import commentReply from "./comment-reply.vue"
export default {
  name: 'Commentcopy',
  components: {
    CommentItem,
    commentReply,
    CommentList
  },
  props: {
    // 点击回复的那行评论信息 
    curComment:{
      type: Object,
      required: true
    }
  },
  data () {
    return {
      commentReplyShow:false,
      commentReplyList:[]
    }
  },
  methods:{
    updataList(val){
      this.commentReplyList.unshift(val.new_obj)
      this.commentReplyShow = false
      this.curComment.reply_count++
    }
  }
}
</script>

<style scoped lang="less">
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}

.reply-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .write-btn {
    width: 60%;
  }
}
.page-bg{
  background-color: #fafafa;
}
.article-bottom {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-sizing: border-box;
    height: 88px;
    border-top: 1px solid #d8d8d8;
    background-color: #fff;
    .comment-btn {
      width: 80%;
      height: 46px;
      border: 2px solid #eeeeee;
      font-size: 30px;
      line-height: 46px;
      color: #a7a7a7;
    }
    .van-icon {
      font-size: 40px;
      .van-info {
        font-size: 16px;
        background-color: #e22829;
      }
    }
  }
</style>